#ifndef NETWORK_H
#define NETWORK_H

#include<QObject>
#include<QTcpSocket>
#include<QTimer>
#include<QHostAddress>

//#pragma execution_character_set("utf-8")

//统计自动测试发送消息次数
static int iCountTestMsg =  0;

class Network : public QObject
{
    Q_OBJECT
public:
    explicit Network(QObject *parent = nullptr);

    ~Network(void);
public:
    //客户端连接服务器
    bool clientConnectToServer(QString serverIpAddress,int serverPort);
    //客户端向服务器发送消息
    void clientSendMsgToServer(QString strData);

    //服务端向客户端发送信息
    void serverSendMsgToClient(QString strData);

    //读取服务器发来的消息
    QByteArray readServerMsg();

public:
    QTcpSocket *socket;//tcp套接字
    QTimer *timer;//定时器

public slots:
    //客户端与服务器之间：断开与连接的操作消息回馈
    void clientConnectedFunc(void);
    void clientDisConnectedFunc(void);

    //断开与服务器(远程主机)的连接
    void disconnectFromHost();


    //启动定时器自动向服务器发送消息
    void startTimerOutFunc();

    //设置停止定时器自动发送消息
    void stopTimerOutFunc();
};

#endif // NETWORK_H
